#pragma once

#include "../serialize/reflect.h"
#include "../serialize/reflect_marshal.h"
#include "../serialize/reflect_tag.h"
#include "../serialize/reflect_unmarshal.h"
#include "../log/Logstream.h"


struct rref {
    std::map<std::string, int> ra;
    std::list<double> rb;

    DECLEAR_META(ra, rb);
    DECLEAR_TAG;
};

IMPLEMENT_TAG(rref, {
    { "ra","RRA,omitempty" },
    { "rb","RRB" }
    });

//static const std::vector<reflect_tag> meta_tag = { { "a","A,empty" },{ "b","B" } };

struct refs {
    uint64_t a;
    std::string b;
    double c;
    std::string d[3];
    unsigned char e[3];
    std::vector<int> f;

    rref g;
    DECLEAR_META(a, b, c, d, e, f, g);
    DECLEAR_TAG;
};

IMPLEMENT_TAG(refs, {
    { "a","INTA,omitempty" },
    { "b","STRINGB" },
    { "f","FFF,omitempty" }
    });


inline void reflect_test()
{
    refs ref;
    ref.a = 0;
    ref.b = "bbb";
    ref.c = 11.123;
    ref.d[0] = "d0";
    ref.d[1] = "d1";
    ref.d[2] = "d2";
    ref.e[0] = 'a';
    ref.e[1] = 'b';
    ref.e[2] = 0;
    ref.f.push_back(200);
    ref.f.push_back(300);

    ref.g.ra["ra1"] = 1111;
    ref.g.ra["ra2"] = 2222;
    ref.g.rb.emplace_back(3.14);
    auto m = ref.reflect_meta_data();

    {
        TIMECAST(cnt);
        for (int i = 0; i < 1; ++i)
        {
            auto j = JsonMarshal(ref);
        }
    }

    auto j = JsonMarshal(ref);

    {
        TIMECAST(cnt);
        for (int i = 0; i < 1; ++i)
        {
            refs rr;
            auto b = JsonUnmarshal(j,rr);
        }
    }
    std::cout << j << std::endl;

    //
    refs uref;
    auto b = JsonUnmarshal(j, uref);
    j = JsonMarshal(uref);
    std::cout << j << std::endl;
}